FROM eclipse-temurin:21-jdk AS builder

RUN apt update && apt install unzip -y

WORKDIR /opt

RUN wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/mvnd/2.0.0-rc-3/maven-mvnd-2.0.0-rc-3-linux-amd64.zip \
&& unzip maven-mvnd-2.0.0-rc-3-linux-amd64.zip

ENV PATH=$PATH:/opt/maven-mvnd-2.0.0-rc-3-linux-amd64/bin

WORKDIR /app

# 缓存依赖
COPY ./pom.xml ./pom.xml

RUN mvnd package -Dmaven.main.skip -Dspring.repackage.skip -Dmaven.test.skip && rm -r target

# 构建产物
COPY ./src ./src

RUN mvnd clean package -Dmaven.test.skip

FROM eclipse-temurin:21-jre-alpine
# 设置工作目录
WORKDIR /app

# 复制本体
COPY --from=builder /app/target/*.jar /app

ENTRYPOINT ["java"]

CMD ["-jar", "springboot-demo-1.0.0.jar", "--spring.profiles.active=prod"]